package com.lino.design.impl;

import com.lino.design.ICouponDiscount;

import java.math.BigDecimal;

/**
 * @description: 直减券
 * @author: lingjian
 * @createDate: 2023/2/9 16:28
 */
public class ZJCouponDiscount implements ICouponDiscount<Double> {

    /**
     * 直减计算
     * 1.使用商品价格减去优惠价格
     * 2.最低支付金额1元
     *
     * @param couponInfo 优惠券信息泛型
     * @param skuPrice   商品价格
     * @return 优惠后价格
     */
    @Override
    public BigDecimal discountAmount(Double couponInfo, BigDecimal skuPrice) {
        BigDecimal discountAmount = skuPrice.subtract(new BigDecimal(couponInfo));
        if (discountAmount.compareTo(BigDecimal.ZERO) < 1) {
            return BigDecimal.ONE;
        }
        return discountAmount;
    }
}
